{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/gee-community/geemap/blob/master/docs/notebooks/103_split_control.ipynb)\n",
    "[![image](https://mybinder.org/badge_logo.svg)](https://gishub.org/geemap-binder)\n",
    "\n",
    "**Creating a split-panel map**\n",
    "\n",
    "This notebook demonstrates how to add a split-panel map with geemap and folium. It also supports streamlit. Note that the ipyleaflet SplitControl does not support streamlit. \n",
    "\n",
    "Uncomment the following line to install [geemap](https://geemap.org) if needed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# !pip install geemap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ee\n",
    "import folium\n",
    "import geemap.foliumap as geemap"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3",
   "metadata": {},
   "source": [
    "The split-panel map requires two layers: `left_layer` and `right_layer`. The layer instance can be a string representing a basemap, or an HTTP URL to a Cloud Optimized GeoTIFF (COG), or a folium TileLayer instance. \n",
    "\n",
    "**Using basemaps**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {},
   "outputs": [],
   "source": [
    "m = geemap.Map(height=500)\n",
    "m.split_map(left_layer=\"TERRAIN\", right_layer=\"OpenTopoMap\")\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5",
   "metadata": {},
   "source": [
    "Show available basemaps."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# geemap.basemaps.keys()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7",
   "metadata": {},
   "source": [
    "**Using COG**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8",
   "metadata": {},
   "outputs": [],
   "source": [
    "m = geemap.Map(height=600, center=[39.4948, -108.5492], zoom=12)\n",
    "url = \"https://github.com/opengeos/data/releases/download/raster/Libya-2023-07-01.tif\"\n",
    "url2 = \"https://github.com/opengeos/data/releases/download/raster/Libya-2023-09-13.tif\"\n",
    "m.split_map(url, url2)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9",
   "metadata": {},
   "source": [
    "**Using folium TileLayer**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10",
   "metadata": {},
   "outputs": [],
   "source": [
    "m = geemap.Map(center=[40, -100], zoom=4)\n",
    "\n",
    "url1 = \"https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2001_Land_Cover_L48/wms?\"\n",
    "url2 = \"https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2019_Land_Cover_L48/wms?\"\n",
    "\n",
    "left_layer = folium.WmsTileLayer(\n",
    "    url=url1,\n",
    "    layers=\"NLCD_2001_Land_Cover_L48\",\n",
    "    name=\"NLCD 2001\",\n",
    "    attr=\"MRLC\",\n",
    "    fmt=\"image/png\",\n",
    "    transparent=True,\n",
    ")\n",
    "right_layer = folium.WmsTileLayer(\n",
    "    url=url2,\n",
    "    layers=\"NLCD_2019_Land_Cover_L48\",\n",
    "    name=\"NLCD 2019\",\n",
    "    attr=\"MRLC\",\n",
    "    fmt=\"image/png\",\n",
    "    transparent=True,\n",
    ")\n",
    "\n",
    "m.split_map(left_layer, right_layer)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11",
   "metadata": {},
   "source": [
    "**Using Earth Engine layers**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12",
   "metadata": {},
   "outputs": [],
   "source": [
    "m = geemap.Map(center=[39.3322, -106.7349], zoom=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13",
   "metadata": {},
   "outputs": [],
   "source": [
    "srtm = ee.Image(\"USGS/SRTMGL1_003\")\n",
    "hillshade = ee.Terrain.hillshade(srtm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "14",
   "metadata": {},
   "outputs": [],
   "source": [
    "vis = {\n",
    "    \"min\": 0,\n",
    "    \"max\": 5000,\n",
    "    \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15",
   "metadata": {},
   "outputs": [],
   "source": [
    "left_layer = geemap.ee_tile_layer(hillshade, name=\"Hillshade\")\n",
    "right_layer = geemap.ee_tile_layer(srtm, vis, name=\"DEM\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16",
   "metadata": {},
   "outputs": [],
   "source": [
    "m.split_map(left_layer, right_layer)\n",
    "m"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
